#include<stdio.h>
#include<unistd.h>
#include<stdlib.h>
#include<sys/wait.h>
#include<sys/types.h>

#define NUM 10
int main()
{
    char* const _env[NUM]={(char*)"MY_VAL=723",NULL};
    pid_t id = fork();
    const char* mypath = "/home/lcq/learn_linux/l_process/exec_test_cmd";
    if(id==0)
    {
        printf("子进程运行,pid:%d\n",getpid());
        sleep(2);
       // char* const _argv[NUM] = {(char*)"ls",(char*)"-a",(char*)"-l",NULL}; 
       // execv("/usr/bin/ls",_argv);  // v：vector
       // execl("/usr/bin/ls","-a","-l",NULL); // l:list
       // execlp("ls","ls","-a","-l",NULL); // p:PATH 表示在环境变量里搜索
       // execvp("ls",_argv); // 同上
        
        execle(mypath,"exec_test_cmd","-a",NULL,_env);
        exit(1);
    }
    else 
    {
        printf("父进程运行，pid:%d\n",getpid());
        int status = 0;

        pid_t res = waitpid(-1,&status,0);

        if(res>0)
        {
            printf("等待成功，子进程退出码为：%d\n",WEXITSTATUS(status));
        }
        
    }
    return 0;
}
